home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2800 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  44 lines

  1. Path: math.ohio-state.edu!usenet
  2. From: Chris Mongold <cmongold@magnus.acs.ohio-state.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: sscanf problems
  5. Date: 24 Jan 1996 04:20:47 GMT
  6. Organization: The Ohio State University, Department of Mathematics
  7. Message-ID: <4e4c2v$j2g@mathserv.mps.ohio-state.edu>
  8. NNTP-Posting-Host: ts33-10.homenet.ohio-state.edu
  9.  
  10. Hello,
  11.     I'm sorry if this is an inappropriate topic, but I've tried
  12. everything else.  I can't seem to get sscanf to to separate a string
  13. into various variable types.  Here is an example:
  14.  
  15. #include <stdio.h>
  16.  
  17. void main()
  18. {
  19. char input[20], crap[17], segment[6], seg_len[3], begin[3], load[3];
  20. int type;
  21. FILE *fp;
  22.  
  23. printf("File: ");
  24. gets(input);
  25.  
  26. fp = fopen(input, "r");
  27.  
  28. while(!feof(fp))
  29. {
  30. fgets(crap, 17, fp);
  31. sscanf(crap, "%d%3s%6s%3s%3s", type, begin, segment, seg_len, load);
  32. printf("%d %3s %6s %3s %3s", type, begin, segment, seg_len, load);
  33.  
  34. }
  35. }
  36. No matter what I do, it always 'bus errors' when I sscanf.  I've tried
  37. it several different ways, including making crap larger, but to
  38. no avail.  If anyone can help me, I would greatly appreciate it.
  39. Please respond to cmongold@magnus.acs.ohio-state.edu 
  40.  
  41. Thanks,
  42.  
  43. Chris 
  44.